/* 
	1.该文件专门用于创建为Count组件服务的reducer
	2.reducer的本质就是一个函数，会收到两个参数：preState、action
*/
import {INCREMENT,DECREMENT} from './constant'

export default function countReducer(preState,action){
	//从action中读取type、data
	const {type,data} = action 
	//根据type类型决定如何加工状态
	switch (type) {
		case INCREMENT: //如果是加
			// console.log('reducer中走了加逻辑',preState,action)
			return preState + data
		case DECREMENT: //如果是减
			return preState - data
		default:
			// console.log('store指挥着reducer去初始化了',preState,action)
			return 0 //初始化状态
	}
}